package com.example.testtouch2;

import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import com.demo.androidgame.fx.Game;
import com.demo.androidgame.fx.Input.TouchEvent;
import com.demo.androidgame.fx.gl.Camera2D;
import com.demo.androidgame.fx.gl.SpriteBatcher;
import com.demo.androidgame.fx.impl.GLScreen;
import com.demo.androidgame.fx.math.OverlapTester;
import com.demo.androidgame.fx.math.Rectangle;
import com.demo.androidgame.fx.math.Vector2;

public class DescriptionScreen extends GLScreen {
	Camera2D guiCam;
	SpriteBatcher batcher;
	Vector2 touchPoint;
	Rectangle goMenu;
	
	public DescriptionScreen(Game game) {
		 super(game);
	        guiCam = new Camera2D(glGraphics, 320, 480);
	        batcher = new SpriteBatcher(glGraphics, 100);
	        touchPoint = new Vector2();
	        goMenu = new Rectangle(160, 30, 160, 50);
	}

	@Override
	public void update(float deltaTime) {
		 List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
	        game.getInput().getKeyEvents();
	        
	        int len = touchEvents.size();
	        for(int i = 0; i < len; i++) {
	            TouchEvent event = touchEvents.get(i);                        
	            if(event.type == TouchEvent.TOUCH_UP) {
	                touchPoint.set(event.x, event.y);
	                guiCam.touchToWorld(touchPoint);
	                
	                if(OverlapTester.pointInRectangle(goMenu, touchPoint)) {
	                
	                    game.setScreen(new menuScreen(game));
	                    return;
	                }
	                
	        	}
	        	        }
	        	}

	@Override
	public void present(float deltaTime) {
		 GL10 gl = glGraphics.getGL();        
	        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
	        guiCam.setViewportAndMatrices();
	        
	        gl.glEnable(GL10.GL_TEXTURE_2D);
		
	        batcher.beginBatch(Assets.gamedescription);
	        batcher.drawSprite(160, 240, 320, 480, Assets.background0Region);
	        batcher.endBatch();
	        
	        batcher.beginBatch(Assets.atlas);
	        batcher.drawSprite(210, 30,  100, 30, Assets.goMenu);
	        batcher.endBatch();  
	        
	        
	        gl.glEnable(GL10.GL_BLEND);
	        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);   
	     	        
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
